package com.birdcage.gamemanagers;

import java.util.HashMap;

import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;

///Singleton
///This class will manage all the resource. (include load, store, release, ect...)
public class ResourceManager 
{
	///Singleton Implement
	static public ResourceManager GetInstance()
	{
		if (m_instance == null)
		{
			m_instance = new ResourceManager();
		}		
		return m_instance;
	}
	private ResourceManager(){};
	private static ResourceManager m_instance = null;
	
	///Public method
	
	///Only load file, won't load directory.
	public FileHandle LoadResource(String path, boolean cache, FileType type)
	{		
		///In our game, we will put all resource at internal path.
		 FileHandle file = m_data.get(path);
		 if (file == null)
		 {
			 file = Gdx.files.getFileHandle(path, type);
			 if (!file.exists() || file.isDirectory())
			 {
				 file = null;
			 }
			 else if(cache)
			 {
				 m_data.put(path, file);
			 }
		 }		
		 return file;
	}
	
	///Default method will load internal file
	public FileHandle LoadResource(String path, boolean cache)
	{
		return LoadResource(path, cache, FileType.Internal);
	}
	
	///Private member
	HashMap<String, FileHandle> m_data = new HashMap<String, FileHandle>();
}
